home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Admin / ad_stylesheets.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  13.6 KB  |  502 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > CSS management functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 4th April 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new ad_settings();
  26.  
  27.  
  28. class ad_settings {
  29.  
  30.     var $base_url;
  31.  
  32.     function ad_settings() {
  33.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  34.  
  35.         switch($IN['code'])
  36.         {
  37.             case 'wrapper':
  38.                 $this->list_sheets();
  39.                 break;
  40.                 
  41.             case 'add':
  42.                 $this->do_form('add');
  43.                 break;
  44.                 
  45.             case 'edit':
  46.                 $this->do_form('edit');
  47.                 break;
  48.                 
  49.             case 'doadd':
  50.                 $this->save_wrapper('add');
  51.                 break;
  52.                 
  53.             case 'doedit':
  54.                 $this->save_wrapper('edit');
  55.                 break;
  56.                 
  57.             case 'remove':
  58.                 $this->remove();
  59.                 break;
  60.                 
  61.             case 'export':
  62.                 $this->export();
  63.                 break;
  64.             
  65.             //-------------------------
  66.             default:
  67.                 $this->list_sheets();
  68.                 break;
  69.         }
  70.         
  71.     }
  72.     
  73.     function export()
  74.     {
  75.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  76.         
  77.         if ($IN['id'] == "")
  78.         {
  79.             $ADMIN->error("You must specify an existing CSS ID, go back and try again");
  80.         }
  81.         
  82.         //+-------------------------------
  83.         
  84.         $DB->query("SELECT * from ibf_css WHERE cssid='".$IN['id']."'");
  85.         
  86.         if ( ! $row = $DB->fetch_row() )
  87.         {
  88.             $ADMIN->error("Could not query the information from the database");
  89.         }
  90.         
  91.         //+-------------------------------
  92.         
  93.         $archive_dir = $INFO['base_dir']."/archive_out";
  94.         
  95.         $css_file    = $INFO['base_dir']."/style_sheets/stylesheet_{$row['cssid']}.css";
  96.         
  97.         if (!is_dir($archive_dir))
  98.         {
  99.             $ADMIN->error("Could not locate $archive_dir, is the directory there?");
  100.         }
  101.         
  102.         if (!is_writeable($archive_dir))
  103.         {
  104.             $ADMIN->error("Cannot write in $archive_dir, CHMOD via FTP to 0755 or 0777 to enable this script to write into it. IBF cannot do this for you");
  105.         }
  106.         
  107.         if (!file_exists($css_file))
  108.         {
  109.             $ADMIN->error("Cannot locate $css_file, please ensure that the file is in the proper directory");
  110.         }
  111.         
  112.         //+-------------------------------
  113.         // Attempt to copy the files to the
  114.         // working directory...
  115.         //+-------------------------------
  116.         
  117.         $l_name = preg_replace( "/\s{1,}/", "_", $row['css_name'] );
  118.         
  119.         $file_name = "css-".$l_name.".css";
  120.         
  121.         if ( ! copy($css_file, $archive_dir."/".$file_name) )
  122.         {
  123.             $ADMIN->error("COPY FAILED ON STYLE SHEET $file_name, maybe the script has insufficient permissions?");
  124.         }
  125.         
  126.         @chmod($archive_dir."/".$file_name, 0777);
  127.         
  128.         $ADMIN->done_screen("Style Sheet Export Created<br><br>You can download the CSS resource <a href='archive_out/$file_name' target='_blank'>here</a>", "Manage Style Sheets", "act=style" );
  129.         
  130.         
  131.     }
  132.     
  133.     
  134.     //-------------------------------------------------------------
  135.     // REMOVE WRAPPERS
  136.     //-------------------------------------------------------------
  137.     
  138.     function remove()
  139.     {
  140.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  141.         
  142.         //+-------------------------------
  143.         
  144.         
  145.         if ($IN['id'] == "")
  146.         {
  147.             $ADMIN->error("You must specify an existing stylesheet ID, go back and try again");
  148.         }
  149.         
  150.         $DB->query("DELETE FROM ibf_css WHERE cssid='".$IN['id']."'");
  151.         
  152.         @unlink( $root_path."style_sheets/stylesheet_{$IN['id']}.css" );
  153.         
  154.         $std->boink_it($SKIN->base_url."&act=style");
  155.             
  156.         exit();
  157.         
  158.         
  159.     }
  160.     
  161.     
  162.     
  163.     //-------------------------------------------------------------
  164.     // ADD / EDIT WRAPPERS
  165.     //-------------------------------------------------------------
  166.     
  167.     function save_wrapper( $type='add' )
  168.     {
  169.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  170.         
  171.         //+-------------------------------
  172.         
  173.         if ($type == 'edit')
  174.         {
  175.             if ($IN['id'] == "")
  176.             {
  177.                 $ADMIN->error("You must specify an existing CSS ID, go back and try again");
  178.             }
  179.             
  180.             $file = $root_path."style_sheets/stylesheet_".$IN['id'].".css";
  181.             
  182.             if ( ! is_writeable($file) )
  183.             {
  184.                 $ADMIN->error("IBF does not have permission to write to that file. Try setting the CHMOD on $file to 0777 and try again. You can do this via FTP");
  185.             }
  186.             
  187.         }
  188.         
  189.         if ($IN['name'] == "")
  190.         {
  191.             $ADMIN->error("You must specify a name for this stylesheet");
  192.         }
  193.         
  194.         if ($IN['css'] == "")
  195.         {
  196.             $ADMIN->error("You can't have an empty stylesheet, can you?");
  197.         }
  198.         
  199.         $css = stripslashes($HTTP_POST_VARS['css']);
  200.         
  201.         $barney = array( 'css_name'     => stripslashes($HTTP_POST_VARS['name']),
  202.                          'css_text'     => $css,
  203.                        );
  204.                        
  205.         if ($type == 'add')
  206.         {
  207.             $db_string = $DB->compile_db_insert_string( $barney );
  208.             
  209.             $DB->query("INSERT INTO ibf_css (".$db_string['FIELD_NAMES'].") VALUES(".$db_string['FIELD_VALUES'].")");
  210.             
  211.             $new_id = $DB->get_insert_id();
  212.             
  213.             $nfile = $root_path."style_sheets/stylesheet_".$new_id.".css";
  214.             
  215.             if ($fh = fopen( $nfile, 'w' ) )
  216.             {
  217.                 fwrite( $fh, $css, strlen($css) );
  218.                 fclose( $fh );
  219.                 
  220.                 @chmod( $nfile, 0777 );
  221.             }
  222.             else
  223.             {
  224.                 $DB->query("DELETE FROM ibf_css WHERE cssid='$new_id'");
  225.             
  226.                 $ADMIN->error("Could not prepare $file for creation - please check the CHMOD value of the 'style_sheets' directory and where possible CHMOD to 0777 via FTP");
  227.             }
  228.             
  229.             $std->boink_it($SKIN->base_url."&act=style");
  230.             
  231.             exit();
  232.             
  233.         }
  234.         else
  235.         {
  236.             $db_string = $DB->compile_db_update_string( $barney );
  237.             
  238.             if ($fh = fopen( $file, 'w' ) )
  239.             {
  240.                 fwrite( $fh, $css, strlen($css) );
  241.                 fclose( $fh );
  242.                 
  243.                 @chmod( $file, 0777 );
  244.                 
  245.                 $DB->query("UPDATE ibf_css SET $db_string WHERE cssid='".$IN['id']."'");
  246.             
  247.                 $ADMIN->done_screen("Stylesheet updated", "Manage Style Sheets", "act=style" );
  248.             }
  249.             else
  250.             {
  251.                 
  252.                 $ADMIN->error("Could not prepare $file for writing - please check the CHMOD value of the 'style_sheets' directory");
  253.             }
  254.             
  255.         }
  256.         
  257.         
  258.     }
  259.     
  260.     //-------------------------------------------------------------
  261.     // ADD / EDIT WRAPPERS
  262.     //-------------------------------------------------------------
  263.     
  264.     function do_form( $type='add' )
  265.     {
  266.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  267.         
  268.         //+-------------------------------
  269.         
  270.         if ($IN['id'] == "")
  271.         {
  272.             $ADMIN->error("You must specify an existing wrapper ID, go back and try again");
  273.         }
  274.         
  275.         //+-------------------------------
  276.         
  277.         $DB->query("SELECT cssid, css_name FROM ibf_css WHERE cssid='".$IN['id']."'");
  278.         
  279.         if ( ! $cssinfo = $DB->fetch_row() )
  280.         {
  281.             $ADMIN->error("Could not query the CSS details from the database");
  282.         }
  283.         
  284.         //+-------------------------------
  285.         
  286.         $file = $root_path."style_sheets/stylesheet_".$IN['id'].".css";
  287.         
  288.         if ( ! file_exists($file) )
  289.         {
  290.             $ADMIN->error("Could not load the stylesheet. No file found at $file");
  291.         }
  292.         
  293.         if ( ! is_readable($file) )
  294.         {
  295.             $ADMIN->error("IBF does not have permission to read from that file. Try setting the CHMOD on $file to 0777 and try again. You can do this via FTP");
  296.         }
  297.         
  298.         //+-------------------------------
  299.         
  300.         $fh  = fopen( $file, 'r' );
  301.         $css = fread( $fh, filesize($file) );
  302.         fclose($fh);
  303.         
  304.         if ($type == 'add')
  305.         {
  306.             $code = 'doadd';
  307.             $button = 'Create StyleSheet';
  308.             $cssinfo['css_name'] = $cssinfo['css_name'].".2";
  309.         }
  310.         else
  311.         {
  312.             // Availability test
  313.         
  314.             if ( ! is_writeable($file) )
  315.             {
  316.                 $ADMIN->error("IBF does not have permission to write to that file. Try setting the CHMOD on $file to 0777 and try again. You can do this via FTP");
  317.             }
  318.             
  319.             $code = 'doedit';
  320.             $button = 'Edit Stylesheet';
  321.         }
  322.         
  323.         //+-------------------------------
  324.     
  325.         $ADMIN->page_detail = "You may use CSS fully when adding or editing stylesheets.";
  326.         $ADMIN->page_title  = "Manage Style Sheets";
  327.         
  328.         //+-------------------------------
  329.         
  330.         $ADMIN->html .= $SKIN->js_no_specialchars();
  331.         
  332.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , $code      ),
  333.                                                   2 => array( 'act'   , 'style'      ),
  334.                                                   3 => array( 'id'    , $IN['id']   ),
  335.                                          ), "theAdminForm", "onSubmit=\"return no_specialchars('csssheet')\""      );
  336.                                          
  337.         //+-------------------------------
  338.         
  339.         $SKIN->td_header[] = array( " "  , "20%" );
  340.         $SKIN->td_header[] = array( " "  , "80%" );
  341.  
  342.         //+-------------------------------
  343.         
  344.         $ADMIN->html .= $SKIN->start_table( $button );
  345.         
  346.         $ADMIN->html .= $SKIN->add_td_row( array( 
  347.                                                     "Stylesheet Title",
  348.                                                     $SKIN->form_input('name', $cssinfo['css_name']),
  349.                                          )      );
  350.                                          
  351.         $ADMIN->html .= $SKIN->add_td_row( array( 
  352.                                                     "Content",
  353.                                                     $SKIN->form_textarea('css', $css, "70", "30"),
  354.                                          )      );
  355.                                                  
  356.         $ADMIN->html .= $SKIN->end_form($button);
  357.                                          
  358.         $ADMIN->html .= $SKIN->end_table();
  359.         
  360.         //+-------------------------------
  361.         //+-------------------------------
  362.         
  363.         $ADMIN->output();
  364.         
  365.         
  366.     }
  367.     
  368.     //-------------------------------------------------------------
  369.     // SHOW STYLE SHEETS
  370.     //-------------------------------------------------------------
  371.     
  372.     function list_sheets()
  373.     {
  374.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  375.         
  376.         $form_array = array();
  377.         $show_array = array();
  378.     
  379.         $ADMIN->page_detail = "You may add/edit and remove stylesheets.<br><br>Style Sheets are CSS files. This is where you can change the colours, fonts and font sizes throughout the board.";
  380.         $ADMIN->page_title  = "Manage Stylesheets";
  381.         
  382.         //+-------------------------------
  383.         
  384.         $SKIN->td_header[] = array( "Title"  , "40%" );
  385.         $SKIN->td_header[] = array( "Allocation"   , "30%" );
  386.         $SKIN->td_header[] = array( "Export" , "10%" );
  387.         $SKIN->td_header[] = array( "Edit"   , "10%" );
  388.         $SKIN->td_header[] = array( "Remove" , "10%" );
  389.         
  390.         //+-------------------------------
  391.         
  392.         $DB->query("SELECT DISTINCT(c.cssid), c.css_name, s.sname from ibf_css c, ibf_skins s WHERE s.css_id=c.cssid ORDER BY c.css_name ASC");
  393.         
  394.         $used_ids = array();
  395.         
  396.         if ( $DB->get_num_rows() )
  397.         {
  398.         
  399.             $ADMIN->html .= $SKIN->start_table( "Current Stylesheets In Use" );
  400.             
  401.             while ( $r = $DB->fetch_row() )
  402.             {
  403.             
  404.                 $show_array[ $r['cssid'] ] .= stripslashes($r['sname'])."<br>";
  405.             
  406.                 if ( in_array( $r['cssid'], $used_ids ) )
  407.                 {
  408.                     continue;
  409.                 }
  410.                 
  411.                 $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['css_name'])."</b>",
  412.                                                           "<#X-{$r['cssid']}#>",
  413.                                                           "<center><a href='".$SKIN->base_url."&act=style&code=export&id={$r['cssid']}'>Export</a></center>",
  414.                                                           "<center><a href='".$SKIN->base_url."&act=style&code=edit&id={$r['cssid']}'>Edit</a></center>",
  415.                                                           "<i>Deallocate before removing</i>",
  416.                                                  )      );
  417.                                                    
  418.                 $used_ids[] = $r['cssid'];
  419.                 
  420.                 $form_array[] = array( $r['cssid'], $r['css_name'] );
  421.                 
  422.             }
  423.             
  424.             foreach( $show_array as $idx => $string )
  425.             {
  426.                 $string = preg_replace( "/<br>$/", "", $string );
  427.                 
  428.                 $ADMIN->html = preg_replace( "/<#X-$idx#>/", "$string", $ADMIN->html );
  429.             }
  430.             
  431.             $ADMIN->html .= $SKIN->end_table();
  432.         }
  433.         
  434.         if ( count($used_ids) > 0 )
  435.         {
  436.         
  437.             $DB->query("SELECT cssid, css_name FROM ibf_css WHERE cssid NOT IN(".implode(",",$used_ids).")");
  438.         
  439.             if ( $DB->get_num_rows() )
  440.             {
  441.             
  442.                 $SKIN->td_header[] = array( "Title"  , "70%" );
  443.                 $SKIN->td_header[] = array( "Export" , "10%" );
  444.                 $SKIN->td_header[] = array( "Edit"   , "10%" );
  445.                 $SKIN->td_header[] = array( "Remove" , "10%" );
  446.             
  447.                 $ADMIN->html .= $SKIN->start_table( "Current Unallocated Stylesheets" );
  448.                 
  449.                 $ADMIN->html .= $SKIN->js_checkdelete();
  450.                 
  451.                 
  452.                 while ( $r = $DB->fetch_row() )
  453.                 {
  454.                     
  455.                     $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['css_name'])."</b>",
  456.                                                                "<center><a href='".$SKIN->base_url."&act=style&code=export&id={$r['cssid']}'>Export</a></center>",
  457.                                                               "<center><a href='".$SKIN->base_url."&act=style&code=edit&id={$r['cssid']}'>Edit</a></center>",
  458.                                                               "<center><a href='javascript:checkdelete(\"act=style&code=remove&id={$r['cssid']}\")'>Remove</a></center>",
  459.                                                      )      );
  460.                                                      
  461.                     $form_array[] = array( $r['cssid'], $r['css_name'] );
  462.                                                        
  463.                 }
  464.                 
  465.                 $ADMIN->html .= $SKIN->end_table();
  466.             }
  467.         }
  468.         
  469.         //+-------------------------------
  470.         //+-------------------------------
  471.         
  472.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'add'      ),
  473.                                                   2 => array( 'act'   , 'style'    ),
  474.                                          )      );
  475.         
  476.         $SKIN->td_header[] = array( " "  , "40%" );
  477.         $SKIN->td_header[] = array( " "  , "60%" );
  478.         
  479.         $ADMIN->html .= $SKIN->start_table( "Create New Stylesheet" );
  480.             
  481.         //+-------------------------------
  482.         
  483.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Base new stylesheet on...</b>" ,
  484.                                                     $SKIN->form_dropdown( "id", $form_array)
  485.                                  )      );
  486.         
  487.         $ADMIN->html .= $SKIN->end_form("Create new stylesheet");
  488.                                          
  489.         $ADMIN->html .= $SKIN->end_table();
  490.         
  491.         //+-------------------------------
  492.         //+-------------------------------
  493.         
  494.         $ADMIN->output();
  495.     
  496.     }
  497.     
  498.     
  499. }
  500.  
  501.  
  502. ?>